%% Author: Hua Hu, Date: 2012-08-22

function [handle, acqinfo, sysinfo] = InitializeGage()
    try
        CsMl_FreeAllSystems;

        systems = CsMl_Initialize;
        CsMl_ErrorHandler(systems);

        [ret, handle] = CsMl_GetSystem;
        CsMl_ErrorHandler(ret);
        
        [ret, sysinfo] = CsMl_GetSystemInfo(handle);
        CsMl_ErrorHandler(ret);
        
        SetupUSB(handle);
        CsMl_ResetTimeStamp(ret);

        [ret] = CsMl_Commit(handle);
        CsMl_ErrorHandler(ret, 1, handle);

        [ret, acqinfo] = CsMl_QueryAcquisition(handle);
%         acqinfo
%         [ret, channelinfo] = CsMl_QueryChannel(handle,1);
%         channelinfo
%         [ret, triggerinfo] = CsMl_QueryTrigger(handle, 1);
%         triggerinfo
        
        fprintf('Gage is initialized successfully.\n');
    catch
        error('There was an error during initialization of GAGE cards.');
    end
    
end